home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-11 | 15.7 KB | 468 lines | [TEXT/KAHL] |
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // //
- // //
- // Copyright PennyWise Software, 1994. //
- // //
- // Part of the PennyWise Software Application Framework //
- // //
- // //
- // TEMPLATE_DIALOG.c Written by Peter Kaplan //
- // //
- // //
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- //
- // This is a template for a PennyWise Software Application Framework window
- //
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- #include "PWFramework.h"
- #include "PWWindowList.h"
- #include "WindowID.h"
- #include "TEMPLATE_DIALOG.h"
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // Directions for customizing this templete to work
- // with your own window types
- //
- // 1 — Rename this file according to the function of the window (Unique Name).
- // Ex. If it is a window for text call the file TextWindow.c
- // 2 - Reame the header file according to the function of the window.
- // 3 - Do a search and replace in this file and the header file.
- // Search for the word TEMPLATE_DIALOG and replace it with the new
- // name of the file from step 1 & 2.
- // 4 — Add this file to the project (Source Menu)
- // 5 - Open "WindowID.h" and add kWINDOW_ID_TEMPLATE_DIALOG value to
- // the list. Just take the next number available
- // 6 - Also in "WindowID.h" increment kMAX_WINDOW_IDS by one.
- // 7 — Add functionality as needed
- // 8 - Add the header file to InitApplication.c file and
- // call Init[xxx]Handlers from InitAppliaction. [xxx] is the name from 1,2 & 3
- // 9 - Add Open calls where needed.
- //
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // These procedures are static. They will only be called by name from here
- // outside refrences will use our window proc list.
- static void ThisWindowCreate (EventRecord* theEvent, WindowPtr theWindow);
- static short ThisWindowDispose (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowZoomIn (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowZoomOut (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowResize (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowClick (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowUpdate (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowActivate (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowDeactivate(EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowDrag (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowIdle (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowCursor (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowKeyDown (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowPreMenu (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowPostMenu (EventRecord* theEvent, WindowPtr theWindow);
- static short ThisWindowDoMenu (EventRecord* theEvent, WindowPtr theWindow, short theMenu, short theItem, short theWindowID);
- static void ThisWindowGrowRect (EventRecord* theEvent, WindowPtr theWindow, Rect* theRect);
- static void ThisWindowBackground(EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowGetScrap (EventRecord* theEvent, WindowPtr theWindow);
- static void ThisWindowPutScrap (EventRecord* theEvent, WindowPtr theWindow);
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // This record holds all the information about this window
- // You can add fields to this record.
- // NOTE:ALL WINDOW RECORDS MUST START WITH THIS
- // HEADER OR ELSE THE FRAMEWORK WILL NOT
- // FUNCTION PROPERLY. YOU'VE BEEN WARNED!
- typedef struct OurWinRecord {
- WindowParamHeader theHeader;
- short isDirty;
- }OurWinRecord, *OurWinPtr, **OurWinHandle;
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // Macros for accessing the header data
- // you can add your own as you add fields
- // to the OurWinRecord.
- // NOTE:THESE MACROS ASSUME theData HOLDS
- // A VALID COPY OF OurWinHandle.
- #define THE_ID (*theData)->theHeader.theID
- #define IS_DIRTY (*theData)->isDirty
- //••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- void InitTEMPLATE_DIALOGHandlers()
- {
- PWInstallWindowType (kWINDOW_ID_TEMPLATE_DIALOG, kWINDOW_TYPE_DIALOG);
- PWInstallCreate (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowCreate);
- PWInstallDispose (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowDispose);
- PWInstallZoomIn (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowZoomIn);
- PWInstallZoomOut (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowZoomOut);
- PWInstallResize (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowResize);
- PWInstallClick (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowClick);
- PWInstallUpdate (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowUpdate);
- PWInstallActivate (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowActivate);
- PWInstallDeactivate (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowDeactivate);
- PWInstallIdle (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowIdle);
- PWInstallCursor (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowCursor);
- PWInstallKeyDown (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowKeyDown);
- PWInstallDrag (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowDrag);
- PWInstallPreMenu (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowPreMenu);
- PWInstallMenu (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowDoMenu);
- PWInstallPostMenu (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowPostMenu);
- PWInstallGrowRect (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowGrowRect);
- PWInstallBackground (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowBackground);
- PWInstallScrap2Appl (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowGetScrap);
- PWInstallAppl2Scrap (kWINDOW_ID_TEMPLATE_DIALOG, ThisWindowPutScrap);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowCreate (EventRecord* theEvent, WindowPtr theWindow)
- {
- // This routine will very rarely contain anything worthwhile
- // You will make custom routines for most windows that will be exported
- // via the include file
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- // Since we will be exporting this we don't have to conform to any particular input format
- void TEMPLATE_DIALOGOpen(void)
- {
- WindowPtr theWindow;
- OurWinHandle theData;
- Rect windowBounds;
-
- SetRect(&windowBounds, 40, 40, 200,200);
- theWindow = NewDialog(NULL,&windowBounds,"\p",FALSE,dBoxProc,(WindowPtr)-1,FALSE,0,NULL);
- if (theWindow) {
- // We sucessfully got the window
-
- // Now we have to allocate our storage
- theData = (OurWinHandle) NewHandle(sizeof(OurWinRecord));
- if (theData) {
- // We sucessfully allocated storage
-
- // So Lets set the port to our new window
- SetPort(theWindow);
-
- // Here we would do any screen/size manipulations
- // before we show the window
-
-
- // Here we would allocate any other
- // objects that we need. (Controls, etc.)
-
- // Now lets set the id
- THE_ID = kWINDOW_ID_TEMPLATE_DIALOG;
- IS_DIRTY = FALSE;
-
- // Install our routines
- SetWRefCon(theWindow, (long) theData);
-
- // Show it & select it before we leave
- ShowWindow(theWindow);
- SelectWindow(theWindow);
- }
- else {
- // We could not allocate memory for our window's data
- // So lets get rid of the data
- DisposeWindow(theWindow);
- theWindow = NULL;
- }
- }
-
- if (!theWindow) {
- SysBeep(1);
- // We did not create the window
- // You will probably want to put up a dialog here to explain why
- }
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static short ThisWindowDispose (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- short theResults;
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Want to save it
- theResults = TRUE;
-
- if (IS_DIRTY) {
- // Data has been changed we would probably want to put up
- // a “Save Changes to x” dialog here
- // But I'm just going to reset IS_DIRTY
- IS_DIRTY = FALSE;
- }
-
- // Do whatever saving you need to do here
-
- // Now lets break it down
- HideWindow(theWindow);
- DisposeHandle((Handle)theData);
- DisposeDialog(theWindow);
-
- return theResults; // True if we closed it, false if we did not [ex. pressed cancel in save dialog]
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowZoomIn (EventRecord* theEvent, WindowPtr theWindow)
- { // The defaults will do the right thing
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowZoomOut (EventRecord* theEvent, WindowPtr theWindow)
- { // The defaults will do the right thing
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowResize (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- EraseRect(&theWindow->portRect);
-
- // Do any control moving here
- //•••••••••••••••••••••••••••
-
- InvalRect(&theWindow->portRect);
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowClick (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
- DialogPtr theDialog;
- short itemHit;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Test for hits here
- //•••••••••••••••••••••••••••
- if( DialogSelect( theEvent, &theDialog, &itemHit)) {
- switch (itemHit) {
- default:
- break;
- }
- }
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowUpdate (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- UpdtDialog( theWindow, theWindow->visRgn);
-
- // Draw the window here
- //•••••••••••••••••••••••••••
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowActivate (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Activate items here
- //•••••••••••••••••••••••••••
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowDeactivate(EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Deactivate items here
- //•••••••••••••••••••••••••••
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowDrag (EventRecord* theEvent, WindowPtr theWindow)
- { // The default does the right thing
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowIdle (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
- DialogPtr theDialog;
- short theItem;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- DialogSelect( theEvent, &theDialog, &theItem);
-
- // do your idle tasks here
- //•••••••••••••••••••••••••••
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowCursor (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Adjust the cursor here
- if (PtInRgn( theEvent->where, ((WindowPeek)theWindow)->strucRgn)) {
- // We are in our window
-
- // More complex comparisons should be happening here
- CopyRgn( ((WindowPeek)theWindow)->strucRgn,gMouseMovedRgn);
-
- // You would want to set it to a different cursor
- SetCursor(&arrow);
- }
- else { // We are outside our window
-
- // Lets make the rgn the whole qd coord
- SetRectRgn(gMouseMovedRgn, -32768, -32768, 32767, 32767);
- // except for our window
- DiffRgn(gMouseMovedRgn,((WindowPeek)theWindow)->strucRgn,gMouseMovedRgn);
- // and set it to an arrow
- SetCursor(&arrow);
- }
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowKeyDown (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
- short keyCode;
- short charCode;
- Point localPoint;
- DialogPtr theDialog;
- short theItem;
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- localPoint = theEvent->where;
- GlobalToLocal(&localPoint);
-
- keyCode = (theEvent->message&keyCodeMask)>>8;
- charCode = theEvent->message&charCodeMask;
-
- DialogSelect( theEvent, &theDialog, &theItem);
-
- // Handle the key click here
-
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowPreMenu (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Enable and disable items
- // change item names etc.
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowPostMenu (EventRecord* theEvent, WindowPtr theWindow)
- {
- OurWinHandle theData;
- GrafPtr oldPort;
-
-
- GetPort(&oldPort);
- SetPort(theWindow);
-
- theData = (OurWinHandle) GetWRefCon(theWindow);
-
- // Enable and disable items
- // change item names etc.
-
-
- SetPort(oldPort);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static short ThisWindowDoMenu (EventRecord* theEvent, WindowPtr theWindow, short theMenu, short theItem, short theWindowID)
- {
- short theResult;
-
- theResult = TRUE;
-
- // if we don't handle it return false so the defaults will pick it up
- switch (theMenu) {
- default:
- theResult = FALSE;
- }
-
- return theResult;
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowGrowRect (EventRecord* theEvent, WindowPtr theWindow, Rect* theRect)
- {
- // This simply is the size of the rect the window can grow to
- SetRect(theRect, 64, 64, 32767, 32767);
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowBackground(EventRecord* theEvent, WindowPtr theWindow)
- {
- // This routine will get called while the window is in the background
- // you may want a window to complete some task while not in the forground, etc.
- // NOTE: If you do not do anything in this routine you can set the
- // windowBackground field to NULL. That will avoid a call
- // THIS IS THE ONLY function that you can do that with!!
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowGetScrap(EventRecord* theEvent, WindowPtr theWindow)
- {
- // This routine will get called when your application gets a resumeEvent
- // AND the convertClipboardFlag bit is set
- // What must be done is the convertion of the clipboard to a private scrap
- TEFromScrap();
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
- static void ThisWindowPutScrap(EventRecord* theEvent, WindowPtr theWindow)
- {
- // This routine will get called when your application gets a suspendEvent
- // What must be done is the convertion of the private scrap to the clipboard
- TEToScrap();
- }
- //•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••